﻿using HttpService.Collect;
using RpcHelper;

namespace HttpService.Config
{
    public class LogConfig
    {
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsEnable
        {
            get;
            set;
        } = false;
        /// <summary>
        /// 日志级别
        /// </summary>
        public LogGrade LogGrade { get; set; } = LogGrade.DEBUG;
        /// <summary>
        /// 日志组
        /// </summary>
        public string LogGroup { get; set; } = "http";

        public bool IsAllHead { get; private set; }
        /// <summary>
        /// 需记录的请求头(*全部)
        /// </summary>
        public string[] RecordHead
        {
            get;
            set;
        } = new string[] { "UserAgent", "UserHostAddress", "UrlReferrer", "HttpMethod", "ContentType" };

        public bool IsAllCookie { get; private set; }
        /// <summary>
        /// 需记录的请求Cookie(*全部)
        /// </summary>
        public string[] RecordCookie
        {
            get;
            set;
        }
        /// <summary>
        /// 需记录的响应头(*全部)
        /// </summary>
        public string[] ResponseHead
        {
            get;
            set;
        }
        internal void Init()
        {
            if (!this.RecordHead.IsNull())
            {
                this.IsAllHead = this.RecordHead.IsExists("*");
            }
            else
            {
                this.IsAllHead = false;
            }
            if (!this.RecordCookie.IsNull())
            {
                this.IsAllCookie = this.RecordCookie.IsExists("*");
            }
            else
            {
                this.IsAllCookie = false;
            }
            ServiceCollect.InitHttpExecution(this);
        }
    }
}
